package com.avic.rong.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.bean.my_message.MessageBean;

import java.util.ArrayList;

public class TradingAdapter extends RecyclerView.Adapter {


    private Context mContext;
    private ArrayList<MessageBean> mList;

    public TradingAdapter(Context mContext, ArrayList<MessageBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_trad, viewGroup, false);
        return new TradingHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        MessageBean messageBean = mList.get(i);
        TradingHolder th = (TradingHolder) viewHolder;

        th.tv_order_status.setText(messageBean.getBusinessName());
        th.tv_order_notice.setText(Html.fromHtml(messageBean.getNewsContent()));
        StringBuffer sb = new StringBuffer();
        String createTime = messageBean.getCreateTime();
        String[] s = createTime.split(" ");
        String[] split = s[0].split("-");
        String substring = s[1].substring(0, 5);


        if(split[1].startsWith("0")){
            String substring1 = split[1].substring(1, 2);
            sb.append(substring1+"月").append(split[2]+"日 ").append(substring);
        }else {
            sb.append(split[1]+"月").append(split[2]+"日 ").append(substring);
        }


        th.tv_createtime.setText(sb);


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class TradingHolder extends RecyclerView.ViewHolder {

        private final TextView tv_order_status;
        private final TextView tv_order_notice;
        private final TextView tv_createtime;

        public TradingHolder(@NonNull View itemView) {
            super(itemView);
            tv_order_notice = itemView.findViewById(R.id.tv_order_notice);
            tv_order_status = itemView.findViewById(R.id.tv_order_status);
            tv_createtime = itemView.findViewById(R.id.tv_createtime);

        }
    }

}
